package com.whxyxj.text3;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Fragment_qdy extends Fragment {
    private String[] hudong = { "左翻身头部", "右翻身头部", "循环左翻身头部", "循环右翻身头部", "人体抬起头部" };
    private String[] xuhao = { "001", "010", "011", "100", "101","110","111" };
    private ListView actlist;
    private List<HashMap<String, Object>> data;
    private final String title = "title";
    private final String ncq = "ncq";
    private final String cq = "cq";
    private final String id = "id";
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_qdy, container, false);
        actlist=view.findViewById(R.id.lv_qqy);
        ListAdapter adapter = null;
        ArrayList<Map<String,Object>> data= new ArrayList<Map<String,Object>>();;
        for (int i = 0; i < hudong.length; i++) {
            Map<String,Object> mapItem = new HashMap<String,Object>();
            mapItem.put(title, hudong[i]);
            mapItem.put(id, xuhao[i]);
            mapItem.put(ncq, "不充气");
            mapItem.put(cq, "充气");
            data.add(mapItem);
        }

        adapter= new  QdySimpleAdapter(
                getActivity(), data, R.layout.qdy_list,
                new String[] { title,ncq,cq,id }, new int[] {
                R.id.tv_title,R.id.bt_ncq,R.id.bt_cq});
        actlist.setAdapter(adapter);
        actlist.setOnItemClickListener(new itemClick());
        return view;
    }
    class itemClick implements OnItemClickListener{

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            Map<String, String> infoMap = (Map<String, String>) parent.getItemAtPosition(position);
            System.out.println(infoMap.get("title"));
            System.out.println(infoMap.get("id"));
        }

    }
}